package org.aceor.mddal.group.util;

import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.exception.ExceptionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.List;

/**
 * Created by lxue on 16/4/9.
 */
public class Parameters {
    private static final Logger log = LoggerFactory.getLogger(Parameters.class);

    public static void setParameter(PreparedStatement ps, List<Object> parameters, String sql) throws SQLException{
        if (CollectionUtils.isEmpty(parameters)) {
            log.info("PreparedStatement#setParameter ==> parameters : Empty, sql :{}",sql);
            return;
        }
        try {
            for (int i = 0; i < parameters.size(); i++) {
                ps.setObject(i, parameters.get(i));
            }
        } catch (SQLException e) {
            log.error("PreparedStatement#setParameter,sql :{}, e :{}", sql, ExceptionUtils.getStackTrace(e));
            throw e;
        }
    }
}
